/**
 * @author Haidar Osman
 */
var RelationArray = function(relatioObjArray,parentShape) {
	this.parentShape=parentShape;	
	this.members = [];
	this.relationObjArray = relatioObjArray;
	var that = this;
	this.addRelation = function(relation) {
		relation.parentShape=that;
		
		this.members[this.members.length] = relation;
		this.relationObjArray.addRelation(relation.relationObj);
		// relation.fromClass.classObj.outgoingRelations.addRelation(this);
		// relation.toClass.classObj.incomingRelations.addRelation(this);
	}
	this.removeRelation = function(fromClass, toClass) {
		var i = 0;
		for( i = 0; i < that.members.length; i++) {
			if(that.members[i].fromClass.classObj.name == fromClass.classObj.name) {
				if(that.members[i].toClass.classObj.name == toClass.classObj.name) {
					that.members.splice(i, 1);
				}
			}
		}
		this.relationObjArray.removeRelation(fromClass.classObj, toClass.classObj);
	}
	
	this.update = function() {
		
		for( i = 0; i < that.relationObjArray.members.length; i++) {
			// var fClass=that.parent
			var type=that.relationObjArray.members[i].type;
			if(type == "uni") {
				var r = new UniRelation(fromClass, toClass, new RelationObj(fromClass.classObj, toClass.classObj, type));
			} else if(type == "generalization") {
				that.removeRelation(toClass, fromClass);
				var r = new GeneralizationRelation(fromClass, toClass, new RelationObj(fromClass.classObj, toClass.classObj, type));

			} else {
				
				var r = new Relation(fromClass, toClass, new RelationObj(fromClass.classObj, toClass.classObj, type));
			}
			var newShape = new BasicShape(that.memberArray.members[i].name, that.isMethod, that, that.memberArray.members[i]);
			newShape.rect.height = height;
			newShape.signature.fontSize = (newShape.rect.height - 2 * newShape.signature.padding) / 2;
			newShape.rect.width = newShape.signature.width + 4 * newShape.signature.padding;
			this.members[this.members.length] = newShape;
			this.parentGroup.add(newShape.group);

		}
	}
	this.getRelation = function(fromClass, toClass) {
		var i = 0;
		for( i = 0; i < that.members.length; i++) {
			if(that.members[i].fromClass.classObj.name == fromClass.classObj.name) {
				if(that.members[i].toClass.classObj.name == toClass.classObj.name) {
					return that.members[i];
					break;
				}
			}
		}
		return null;
	}
}